﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SwAddinHelpers.Sinks;
using  SwAddinHelpers.Base;

using SolidWorks.Interop.swconst;

using System.Reflection;

namespace SwAddinHelpers.Attributes
{

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
    public class SinkMethodAttribute : Attribute
    {
        public enumEventSink SourceEvent { get; set; }
        public bool TieOnHostCreation { get; set; }
        public MethodInfo methodInfo { get; set; }

        public SinkMethodAttribute(enumEventSink sourceEvent, bool tieOnHostCreation = false)
        {
            SourceEvent = sourceEvent;
            TieOnHostCreation = tieOnHostCreation;
        }
    }

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
    public class InvokableMethodAttribute : Attribute
    {
        public string FriendlyName { get; set; }

        public InvokableMethodAttribute(string friendlyName)
        {
            FriendlyName = friendlyName;
        }
    }

    [AttributeUsage(AttributeTargets.Class)]
    public class SwAddinAttribute : Attribute
    {
        public string Description = "";
        public bool LoadAtStartup;
        public string Title = "";
    }

    #region Used to define external control host type

    [AttributeUsage(AttributeTargets.Class)]
    public abstract class HostedAsAttribute : Attribute
    {   
        public HostedAsAttribute()
        {
        }
    }
    
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class HostedAsForm : HostedAsAttribute
    {
        public string WindowCaption;

        public HostedAsForm(string caption)
        {
            WindowCaption = caption;
        }
    }

    [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
    public class HostedAsTaskpane : HostedAsAttribute
    {
    	public string Bitmap;
    	public string ToolTip;
    	
        public HostedAsTaskpane(string bitmapPath = "", string toolTip = "External TaskPane")
        {
        	Bitmap = bitmapPath;
        	ToolTip = toolTip;
        }
    }
    
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class HostedAsFeatureView : HostedAsAttribute
    {
    	public string BitMapFile;
    	public string ToolTip;
        public SolidWorks.Interop.swconst.swFeatMgrPane_e WhichPane;
        public bool AutoGenerateView;
        public double SplitterPosition;
        public bool NotifyUserOfCreationFailure;
        public bool IsHost;

        public HostedAsFeatureView(
        	string bitMapFile = "",
        	string toolTip = "External Feature View",
            SolidWorks.Interop.swconst.swFeatMgrPane_e whichPane = SolidWorks.Interop.swconst.swFeatMgrPane_e.swFeatMgrPaneTop,
            double splitterPosition = 0.0,
            bool IsHostForPropertyPages = false,
            bool autoGenerateView = true,
            bool notifyUserOfCreationFailure = true)
        {
        	BitMapFile = bitMapFile;
        	ToolTip = toolTip;
            SplitterPosition = splitterPosition;
            WhichPane = whichPane;
            AutoGenerateView = autoGenerateView;
            NotifyUserOfCreationFailure = notifyUserOfCreationFailure;
            IsHost = IsHostForPropertyPages;
        }
    }

    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class HostedAsModelView : HostedAsAttribute
    {
        public string UniqueName;

        public HostedAsModelView(string uniqueName)
        {
            UniqueName = uniqueName;
        }
    }

    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class HostedAsPropertyPage : HostedAsAttribute
    {
        public string Title;
        public string Caption;
        public string ToolTip;
        public int Options; //Options as defined in swPropertyManagerPageOptions_e
        public bool IsHosted; 

        public HostedAsPropertyPage(string title = "My Property Manager",
                                    string caption = "My Property Manager Control",
                                    string toolTip = "My Control Tooltip",
                                    int options = (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_OkayButton | 
                                    	(int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_CancelButton,
            						bool IsHostedByFeatureView = false)
        {
        	Title = title;
        	Caption = caption;
        	ToolTip = toolTip;
        	Options = options;
            IsHosted = IsHostedByFeatureView;
        }
    }

    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class CommandGroupDefinitionAttribute : Attribute
    {
        public string groupName;
        public SolidWorks.Interop.swconst.swDocumentTypes_e documentTypes;
        public int documentTypesAsInt;
        public bool hasMenu;
        public bool hasToolbar;
        public string bmpImageStripPath;

        public CommandGroupDefinitionAttribute(
            string GroupName,
            SolidWorks.Interop.swconst.swDocumentTypes_e DocumentTypes,
            bool HasMenu,
            bool HasToolbar,
            string BmpImageStripPath)
        {
            documentTypes = DocumentTypes;
            groupName = GroupName;
            hasMenu = HasMenu;
            hasToolbar = HasToolbar;
            bmpImageStripPath = BmpImageStripPath;
            documentTypesAsInt = (int)documentTypes;
        }

    }

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public class CommandItemCallbackAttribute : Attribute
    {
        public string commandGroupName;
        public string commandItemName;
        public string commandItemEnableMethod ;
        public string commandItemToolTip ;
        public bool isMenuItem;
        public bool isToolbarItem;
        public int imageIndex;

        public CommandItemCallbackAttribute(
            string CommandGroupName,
            string CommandItemName,
            string CommandItemEnableMethod = null,
            string CommandItemToolTip = null,
            bool IsMenuItem = true,
            bool IsToolbarItem = false,
            int ImageIndex = 0)
        {
            commandGroupName = CommandGroupName;
            commandItemName = CommandItemName;
            commandItemEnableMethod = CommandItemEnableMethod;
            commandItemToolTip = CommandItemToolTip;
            isMenuItem = IsMenuItem;
            isToolbarItem = IsToolbarItem;
            imageIndex = ImageIndex;
        }
    }

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public class MenuItemCallbackAttribute : Attribute
    {
        public SolidWorks.Interop.swconst.swDocumentTypes_e[] documentTypes;
        //public int documentTypesAsInt;
        public string menuItemName;
        public string menuItemEnableMethod ;
        public string menuItemToolTip;
        public SolidWorks.Interop.swconst.swMenuIdentifiers_e parentMenu;
        public int menuItemPosition;
        public bool menuHasParent;

        public MenuItemCallbackAttribute(
            SolidWorks.Interop.swconst.swDocumentTypes_e[] DocumentTypes,
            string MenuItemName,
            string MenuItemEnableMethod = null,
            string MenuItemToolTip = null,
            bool MenuHasParent = false,
            SolidWorks.Interop.swconst.swMenuIdentifiers_e ParentMenu = SolidWorks.Interop.swconst.swMenuIdentifiers_e.swToolsMenu,
            int MenuItemPosition = -1)
            //http://geekswithblogs.net/abhijeetp/archive/2009/01/10/dynamic-attributes-in-c.aspx
        {
            documentTypes = DocumentTypes;
            menuItemName = MenuItemName;
            menuItemEnableMethod = MenuItemEnableMethod;
            menuItemToolTip = MenuItemToolTip;
            parentMenu = ParentMenu;
            menuItemPosition = MenuItemPosition;
            menuHasParent = MenuHasParent;

            //documentTypesAsInt = (int)documentTypes;
        }
    }

    #endregion
}
